﻿using ET;
using UnityEngine;

namespace Core
{
    public class SceneItemMgr : Entity, IAwake
    {
        private float deathTime = 5;

        void IAwake.Awake()
        {
            // read config deathTime
        }
        public async ETTask CreateItem(int itemId, int count, Vector3 position)
        {
            var config = World.GetComponent<ConfigComponent>().GetConfig<ItemConfig>(itemId);
            if (config == null)
                return;
            
            var prefab = await World.GetComponent<ResourceComponent>().LoadAsync<GameObject>(config.model);
            var transform = prefab != null ? GameObject.Instantiate(prefab).transform : null;
            var sceneItem = this.AddChild<SceneItem, Transform,int, float>(transform, count, deathTime);
            sceneItem.Position = position;
        }
    }
}
